package br.trainee.web.componentes;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import br.trainee.web.util.ResponseWrapper;

public class SliderTag extends BodyTagSupport {

	private static final long serialVersionUID = 1L;

	private String animate;
	private String disabled;
	private String orientation;
	private String max;
	private String min;
	private String range;
	private String value;
	private String step;

	@Override
	public int doEndTag() throws JspException {

		String slider = getBodyContent().getString();

		JspWriter saida = pageContext.getOut();

		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();

		request.setAttribute("slider", slider);
		request.setAttribute("animate", animate);// manda como atributo
		request.setAttribute("disabled", disabled);
		request.setAttribute("orientation", orientation);
		request.setAttribute("max", max);
		request.setAttribute("min", min);
		request.setAttribute("range", range);
		request.setAttribute("value", value);
		request.setAttribute("step", step);

		ResponseWrapper responseWrapper = new ResponseWrapper(response);

		RequestDispatcher req = request.getRequestDispatcher("/resources/componentes-jsp/slider.jsp");

		try {

			req.include(request, responseWrapper);

			String conteudoComponente = responseWrapper.getString();// nessa linha a interpretação já foi feita

			saida.print(conteudoComponente);

		} catch (IOException | ServletException e) {

			e.printStackTrace();
		}

		return super.doEndTag();
	}

	
	/**************************************/
	public String getAnimate() {
		return animate;
	}

	public void setAnimate(String animate) {
		this.animate = animate;
	}

	public String getDisabled() {
		return disabled;
	}

	public void setDisabled(String disabled) {
		this.disabled = disabled;
	}

	public String getOrientation() {
		return orientation;
	}

	public void setOrientation(String orientation) {
		this.orientation = orientation;
	}

	public String getMax() {
		return max;
	}

	public void setMax(String max) {
		this.max = max;
	}

	public String getMin() {
		return min;
	}

	public void setMin(String min) {
		this.min = min;
	}

	public String getRange() {
		return range;
	}

	public void setRange(String range) {
		this.range = range;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getStep() {
		return step;
	}

	public void setStep(String step) {
		this.step = step;
	}

}
